/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package se_juegos;

import Inference.Configuracion;
import Inference.Constants;
import Inference.OntologyAccess;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.ToolTipManager;

/**
 *
 * @author FERNANDO MORENO
 */
public class PanelJuego extends javax.swing.JPanel {

    /**
     * Creates new form PanelJuego
     */
    public PanelJuego() {
        initComponents();
        this.revalidate();
    }
    public void setJuego(Integer num , String nombre){
        ToolTipManager.sharedInstance().setDismissDelay(15000);
        List<String> nombres = OntologyAccess.getPropiedadesJuegosData(nombre, Constants.PROPIEDAD_NOMBRE);
        String nombreJuego = nombres.size() >0 ? nombres.get(0): "";
        List<String> imagenes = OntologyAccess.getPropiedadesJuegosData(nombre, Constants.PROPIEDAD_URL_IMAGEN);
        String imgURL = imagenes.size() > 0 ? imagenes.get(0):"http://cdn.akamai.steamstatic.com/steam/apps/7670/header_292x136.jpg?t=1392365692";
        this.lblName.setText(nombreJuego);
        num = num+1;
        this.lblNumber.setText(num.toString());
        if(!Configuracion.offline){
        Image gameImage = null;
        try {
            URL url = new URL(imgURL);
            BufferedImage image = ImageIO.read(url);
            gameImage = image.getScaledInstance(this.lblImagen.getPreferredSize().width, this.lblImagen.getPreferredSize().height,Image.SCALE_SMOOTH);
        } catch (IOException e) {
        	e.printStackTrace();
        }
        this.lblImagen.setIcon(new ImageIcon(gameImage));
        }
        else{
            this.lblImagen.setText("No se puede mostrar la imagen");
        }
        String explicacion = SE_juegos.motor.obtenerExplicacionJuego(nombre);
        explicacion = explicacion.replace("\n", "<br>");
        explicacion = "<html>"+ explicacion + "</html>";
        this.lblImagen.setToolTipText(explicacion);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblNumber = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        lblImagen = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(139, 130));

        lblNumber.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblNumber.setText("#");

        lblName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblName.setText("Juego");

        lblImagen.setText("Imagen");
        lblImagen.setPreferredSize(new java.awt.Dimension(119, 80));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblNumber)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblName)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNumber)
                    .addComponent(lblName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblImagen;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblNumber;
    // End of variables declaration//GEN-END:variables
}
